const uglify = require("gulp-uglify");
const path = require("path");
const gulp = require("gulp");
const jsobfuscator = require("gulp-javascript-obfuscator");

const workSpaceDir = path.resolve(__dirname, "../");

module.exports = publish;

function publish(targetPath) {
    return gulp.src(path.join(workSpaceDir, "bin/js/bundle.js"))
        .pipe(uglify({
            mangle: {
                eval: true,

                keep_fnames: false,

                toplevel: true
            },

            output: {
                ascii_only: true,

                /**美化js */
                beautify: false,
            },

            compress: {
                arguments: true,

                assignments: true,

                /**删除无法访问代码 */
                dead_code: true,

                /**删除冗余指令 */
                directives: true,

                /**删除打印 */
                drop_console: true,
            }

        }))
        .pipe(jsobfuscator({
            log: false,

            sourceMap: true,
        }))
        .pipe(gulp.dest(path.join(workSpaceDir, "release", targetPath, "js")))
}




